﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ContractSP_ExtendForm.aspx.vb" Inherits="PubProject.ContractSP_ExtendForm" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o="urn:schemas-microsoft-com:office:office">
	<HEAD>
		<title></title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
		<script language="javascript" src="/_common/scripts/global.js"></script>
		<script language="javascript" src="/_controls/settings.aspx"></script>
		<script language="javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/_controls/number/number.js"></script>
		<script language="javascript" src="/_controls/datetime/date.js"></script>
		<script language="javascript" src="/MyWorkflow/Workflow.js"></script>
		<script language="javascript" src="/MyWorkflow/Blank.js"></script>
		<script language="javascript" src="/PubProject/js/Public.js"></script>		
		<script language="javascript" src="/CBGL/JS/BudgetCostUse.js"></script>
		<script language="javascript" src="/CBGL/JS/StockCostUse.js"></script>
		<script language="javascript" src="/Qmys/JS/DeptUseInfo.js"></script>
		<script language="javascript" src="/CBGL/JS/Public.js"></script>
		<script language="javascript" src="/CBGL/JS/ContractPub.js"></script>	
		<script language="javascript" src="/Qmys/JS/Public.js"></script>
		<style> body{font-size:9pt;}
	        table{font-size:9pt;}
	        P{font-size:9pt;}
		</style>
		<LINK href="/MyWorkflow/css/form.css" type="text/css" rel="stylesheet">
		<script language="javascript">
		    var ObjBudgetCostUse = null;//选择合约规划类
			var ObjStockCostUse = null; //选择公司库存类
			var IfDdhs=null;            //是否单独执行
			var sCfTypeName,sCfSouce,sRefType,sRefGUID,sMasterContractGUID,sContractGUID;
			var IsLicenseQmys = IsLicenseApp("费用预算");   //是否启用了全面预算
			
			var sProjType = ""
			var sSignDate = ""
			var sHtAmount = ""
			
			/*------------------------------------------------------------------*/
			//表单接口函数，需扩展
			//1、Fill	--	表单填充
			//2、GetXML --	表单取数
			//3、Valid	--	表单校验
			/*------------------------------------------------------------------*/
			//屏避右键
			function document.oncontextmenu()
			{
				var s = event.srcElement.tagName;
				// For Selection Ranges, s will be UNDEFINED
				if (s && s != "INPUT" && s != "TEXTAREA" || event.srcElement.disabled || document.selection.createRange().text.length == 0)
				{
					event.returnValue = false;
				}
			}
			//功能：表单填充
			//editableDomainList	当前步骤可编辑域
			//invisibleDomainList   当前步骤不可见域
			//domainXML				域XML
			function Fill(editableDomainList,invisibleDomainList,domainXML)
			{
				var xmlDom = new ActiveXObject("Microsoft.XMLDOM"); 
				if (domainXML && domainXML.length>0)	
				{		
					xmlDom.async=false; 
					xmlDom.loadXML(domainXML);
					
					if(xmlDom.parseError.errorCode != 0) 
						xmlDom = null; 
				}
				else
				{
					xmlDom = null;
				}
 
				Form1.ContractCode.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同编号']").text;
				Form1.ContractName.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同名称']").text;				
				Form1.ProjectNameList.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='所属项目']").text;				
				Form1.HtTypeName.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同类别']").text;
				Form1.JfProviderName.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='甲方单位']").text;
				Form1.YfProviderName.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='乙方单位']").text;
				Form1.HtAmount_Bz.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='有效签约金额(￥)']").text;
				Form1.SignDate.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同签约时间']").text;
				Form1.Jbr.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='经办人']").text;
				Form1.JbDeptName.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='经办部门']").text;
				
				Form1.TextArea1.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同要点及经办部门意见']").text;
				Form1.UseCostInfo.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合约规划']").text;	
				Form1.UseStockInfo.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='公司库存']").text;	
				Form1.DeptUseInfo.value = xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='部门费用']").text;
				
				Form1.UseCostInfo.style.cursor = "hand"
	            Form1.UseCostInfo.style.textDecorationUnderline = "true"
				
				var objlist = getHTMLDomainField(document);
				
				for(var i=0;i<objlist.length;i++)
				{ 	
					if((invisibleDomainList+",").indexOf(objlist[i].dm_name + ',')>-1)
					{
						//不可见域不显示
						objlist[i].style.display="none";
					}
				
					//不可编辑的disabled,可编辑的enabled
					if((editableDomainList+",").indexOf(objlist[i].dm_name + ',')>-1)
					{
						objlist[i].readOnly =false;
					}
					else
					{
						objlist[i].readOnly =true;
					}
				}
				sContractGUID = xmlDom.selectSingleNode("/BusinessType").attributes.getNamedItem("BusinessGUID").value;
				//相关附件
				if (sContractGUID != "")
				{
				    var sMode="";
				    sMode=requestURL("mode");
				    if(sMode=="3"){
					    document.all["appIfraFJ"].src = "/PubProject/Pub/DocumentUpFile.aspx?FKGUID=" + escape(sContractGUID) + "&UpFileState=LOOK&IsAllowOpenFile=true&Title=" + escape("合同附件") + "&DocType=" + escape("合同登记");
				    }else{
					    document.all["appIfraFJ"].src = "/PubProject/Pub/DocumentUpFile.aspx?FKGUID=" + escape(sContractGUID) + "&UpFileState=EDIT&IsAllowOpenFile=true&Title=" + escape("合同附件") + "&DocType=" + escape("合同登记");
				    }
				}
				
				//获得合同的合约规划使用XML、及中间科目使用类
				GetBudgetXml(sContractGUID);
                
                //没有启用成本则隐藏合约规划
	            if(Form1.txtLicenseCbgl.value=="0"){
	                document.all("tBudgetInfo").style.display = "none";
	                document.all("tStockInfo").style.display = "none";              
	            }

			    if(IsLicenseQmys != 1){
			        document.all("tDeptUseInfo").style.display = "none";
			    }else{
			        document.all("tDeptUseInfo").style.display = "";
			    }

	            if(sProjType == "无项目"){
	                 document.all("tBudgetInfo").style.display = "none";
	                 document.all("tStockInfo").style.display = "none";	      
	                 if(IsLicenseQmys == "0") document.all("UseCostInfoTr").style.height = "0";          
	            }else{
	                 document.all("tDeptUseInfo").style.display = "none";	                
	            }
			}
			
			//前端截取URL地址获取mode值
			function requestURL(paras){ 
                var url = location.href; 
                var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); 
                var paraObj = {} ;
                for (i=0; j=paraString[i]; i++){ 
                    paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length); 
                } 
                var returnValue = paraObj[paras.toLowerCase()]; 
                if(typeof(returnValue)=="undefined"){ 
                    return ""; 
                }else{ 
                    return returnValue; 
                } 
            } 			
			
			//功能：表单取数
			//参数：取值前的domainxml
			//返回值 取值后的domainxml
			function GetXML(domainXML)
			{
				var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
				 
				xmlDom.async=false;
				xmlDom.loadXML(domainXML);
						
				if(xmlDom.parseError.errorCode != 0) return "";
				 
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同编号']").text = Form1.ContractCode.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同名称']").text = Form1.ContractName.value;				
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='所属项目']").text = Form1.ProjectNameList.value;				
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同类别']").text = Form1.HtTypeName.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='甲方单位']").text = Form1.JfProviderName.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='乙方单位']").text = Form1.YfProviderName.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='有效签约金额(￥)']").text = Form1.HtAmount_Bz.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同签约时间']").text = Form1.SignDate.value;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='经办人']").text = Form1.Jbr.value ;
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='经办部门']").text = Form1.JbDeptName.value;				
				xmlDom.selectSingleNode("/BusinessType/Item/Domain[@name='合同要点及经办部门意见']").text = Form1.TextArea1.value;
				
				return xmlDom.xml;	
			}
			
			//功能：表单校验
			//参数：可编辑域列表
			function Valid(editableDomainList)
			{
				return true;
			}
			
			//功能：发起审批时校验			
			function InitValidate()
			{				
				//获得合同的合约规划使用XML、及中间科目使用类
				GetBudgetXml(sContractGUID);
				
				if(!CheckContractIfAmountEqual(ObjBudgetCostUse,ObjStockCostUse,ObjDeptUseInfo,"",sContractGUID,sProjType,IfDdhs,sHtAmount,false,false)) return false;    //提交审批时添加金额是否等于拆分金额之和的校验
				
				if(!CheckHtCostCompel(ObjBudgetCostUse,sContractGUID,IfDdhs,"发起审批",false,true)) return false;
			    if(UpdateContractState(sContractGUID, "ProcessLaunchCheck"))
			    {
			        return true;
			    }
				return false;
			}
			
			function GetBudgetXml(sContractGUID)
			{
			    var sFile = "/Cbgl/HTDL/HTDL_XMLHTTP.aspx?ContractGUID=" + escape(sContractGUID);
				
				var sRtn = openXMLHTTP(sFile,"GetSPRefInfo");
				
                if (""!=sRtn)
                {
                    //返回  sContractGUID|RefGUID|RefType|CfSouce|CfTypeName|IfDdhs
                    var sRtnList = sRtn.split("|")
                    sMasterContractGUID = sRtnList[0];
                    RefGUID = sRtnList[1];
                    RefType = sRtnList[2];
                    CfSouce = sRtnList[3];
                    CfTypeName = sRtnList[4];
                    IfDdhs = sRtnList[5];
                   
                     sProjType = sRtnList[6];
                    sHtAmount = sRtnList[7];
                    sSignDate = sRtnList[8];        
                    
                                    
                    ObjBudgetCostUse = new BudgetCostUse(sContractGUID,RefGUID,sRefType,sCfSouce,sCfTypeName,"合同");
				    ObjStockCostUse = new StockCostUse(sMasterContractGUID,RefGUID,sRefType);	
                                        
 	                if(IfDdhs == "1"){
	                    ObjDeptUseInfo = new DeptUseInfo(sContractGUID,sContractGUID,"合同","","","","","",sSignDate);
	                }else{
	                    ObjDeptUseInfo = new DeptUseInfo(sMasterContractGUID,sContractGUID,"变更","","","","","",sSignDate);
	                }	
               }
			}
			

            function ChgUseCost()
            {
                //aobo add on 20081028 选择合约规划
	            if (null==ObjBudgetCostUse)
	            {	            
	                 return; 	
	            }
            	
	            if (document.readyState != "complete")
	            {
		            alert("当前页面没有加载完，请稍候保存！");
		            event.returnValue = false;
	                return;
	            }
	            var mode = "3";            	
	            var kFtAmount = stringToFloat(Form1.HtAmount_Bz.value) - stringToFloat(ObjStockCostUse.GetYCfAmount());            	
	                //如果单独付款             	   
	            if(IfDdhs=="1")	
	            {	               
	                if(ObjBudgetCostUse.UpdateData(kFtAmount,mode,'0','0','1'))
	                {    		
		               
	                }
	             }//if(Form1.IfDdhs.value=="1")	
	             else//
	             {
		            //alert('非单独执行合同选择合约规划');
		            ObjBudgetCostUse.selectAlterBudget_Contract('变更','其它变更', RefGUID, sContractGUID,sMasterContractGUID,Form1.HtAmount_Bz.value); 			 
            			
	             }
            }


            function SelectCompStock()
	        {
	            //aobo add 20081028 增加选择公司库存
	            // aobo add on 20081028
		        if (document.readyState != "complete")
		        {
			        alert("当前页面没有加载完，请稍候保存！");
			        event.returnValue = false;
		            return;
		        }	
        		
		        //aobo add on 20081028 选择司库存
	            if (null==ObjStockCostUse) return; 
        		
		        var mode =  "3";
        	   		
		        //选择公司库存界面
		        //分摊金额，新增时，需要将合同金额减去选择合约规划金额
		        var kFtAmount = stringToFloat(Form1.HtAmount_Bz.value) - stringToFloat(ObjBudgetCostUse.GetYCfAmount());
		        if(ObjStockCostUse.UpdateData(kFtAmount,mode))
	            {
        		     
		         }	 
        		 
        		  	
	        }
	
	    //显示部门费用
	    function SelectDeptUseInfo(){ 
	        var mode = "3";    	
	        //分摊金额，即合同有效签约金额
	        ObjDeptUseInfo.UpdateDeptUseInfo(sHtAmount,mode,false);
	    }	
        //
        //aobo add on 20081016 显示合约规划信息
        //	
//         function openViewLayer(vBudgetList)
//         {
//            if (vBudgetList.value ==undefined  || vBudgetList.value=="")  return false;
//	        var xmlBudget;
//	        var i;
//	        var sBudgetGUID=""; 
//     
//	        xmlBudget = ObjBudgetCostUse.DataXml;
//	        iRow =xmlBudget.getElementsByTagName("cb_BudgetUse/DataList/Row").length;
//	        for(i=0;i<iRow;i++)
//	        {
//		        node = xmlBudget.getElementsByTagName("cb_BudgetUse/DataList/Row")(i);        		
//		       
//		        sBudgetGUID=sBudgetGUID + ""+node.attributes.getNamedItem("BudgetGUID").text+",";
//	        }	
//	        if(sBudgetGUID!="")
//	        {
//	          sBudgetGUID = sBudgetGUID.substring(0,sBudgetGUID.lastIndexOf(","))
//	          createBg(); 
//              createCon(sBudgetGUID); 
//	        }
//	        else
//	        {
//	           return false; 
//	        }
//            
//         }


         function openViewLayer(vBudgetList)
         {
          
            if (vBudgetList.value ==undefined  || vBudgetList.value=="")  return false;

	        var xmlBudget;
	        var i;
	        var sBudgetGUID;
        	
	        sBudgetGUID="";

	        xmlBudget = ObjBudgetCostUse.DataXml;
	        iRow =xmlBudget.getElementsByTagName("cb_BudgetUse/DataList/Row").length;
	        for(i=0;i<iRow;i++)
	        {
		        node = xmlBudget.getElementsByTagName("cb_BudgetUse/DataList/Row")(i);		
        		
		        sBudgetGUID=sBudgetGUID + ""+node.attributes.getNamedItem("BudgetGUID").text+",";
	        }	
	        if(sBudgetGUID!="")
	        {
	          sBudgetGUID = sBudgetGUID.substring(0,sBudgetGUID.lastIndexOf(","))
	          document.all("appDemoIframe").src = "/Cbgl/PUB/SelectBudgetPath.aspx?mode=3&BudgetGUID="+sBudgetGUID
	          ShowViewLayer(true);
	        }
	        else
	        {
	           return false; 
	        }
            
         }
			
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout" id="bodyId">
		
		  <div id="bgDiv" style="display:none;background-color:white;position:absolute;left:0px;top:0px;height:300px;width:400px;" onmouseout="ShowDeptUseViewLayer(false)">
			<table> <tr> <td> <table> <tr> <td> <iframe id='appDemoIframe' src='' frameborder='no' height='300' width='400' scrolling='auto'></iframe> </td> </tr> </table> </td> </tr> </table>
      </div>	
	
		<form id="Form1" method="post" runat="server">
			<asp:textbox id="ApplyUserGUID" runat="server" style="display:none"></asp:textbox>
			<asp:textbox id="ApplyDeptGUID" runat="server" style="display:none"></asp:textbox>
			<asp:textbox id="ResultTypeGUID" runat="server" style="display:none"></asp:textbox>
			<asp:textbox id="WorkResultGUID" runat="server" style="display:none"></asp:textbox>	
			<asp:textbox id="txtLicenseCbgl" style="DISPLAY: none" Runat="server"></asp:textbox>

			<TABLE width="100%">
				<TBODY>
					<TR>
						<TD><!-- 表单 -->
							<P align="center" id="pTitle"><FONT style="FONT-SIZE: 16px"><STRONG>合同审批表</STRONG></FONT></P>
							<P align="center">
								<TABLE style="TABLE-LAYOUT: fixed; WIDTH: 90%; BORDER-COLLAPSE: collapse" borderColor="#517dbf"
									cellSpacing="2" cellPadding="3" align="center" bgColor="#ffffff" border="1">
									<colgroup>
										<col width="110">
										<col>
										<col width="110">
										<col>										
									</colgroup>
									<TR height="25">
										<TD>
											合同编号
										</TD>
										<TD>
											<INPUT class="txt" id="ContractCode" style="WIDTH: 100%; HEIGHT: 100%" maxLength="4000"
												dm_name="合同编号">
										</TD>
										<TD>
											合同名称
										</TD>
										<TD >
											<INPUT class="txt" id="ContractName" style="WIDTH: 100%; HEIGHT: 100%" maxLength="100" dm_name="合同名称"> 
										</TD>
									</TR>
									<TR height="25">
										<TD>
											所属项目
										</TD>
										<TD>
											<INPUT class="txt" id="ProjectNameList" style="WIDTH: 100%; HEIGHT: 100%" maxLength="4000"
												dm_name="所属项目">
										</TD>
										<TD>
											合同类别
										</TD>
										<TD >
											<INPUT class="txt" id="HtTypeName" style="WIDTH: 100%; HEIGHT: 100%" maxLength="100" dm_name="合同类别"> 
										</TD>
									</TR>
									<TR height="25">
										<TD>
											甲方单位
										</TD>
										<TD colspan=3>
											<INPUT class="txt" id="JfProviderName" style="WIDTH: 80%; HEIGHT: 100%" maxLength="4000"
												dm_name="甲方单位">
										</TD>
										
									</TR>
									<TR height="25">
										<TD>
											乙方单位
										</TD>
										<TD colspan=3>
											<INPUT class="txt" id="YfProviderName" style="WIDTH: 80%; HEIGHT: 100%" maxLength="4000"
												dm_name="乙方单位">
										</TD>										
									</TR>
									
									<TR height="25">
										<TD>
											有效签约金额(￥)
										</TD>
										<TD>
											<INPUT class="num" id="HtAmount_Bz" style="WIDTH: 100%; HEIGHT: 100%" maxLength="20" dm_name="有效签约金额" acc="2">
										</TD>
										<TD>
											合同签约日期
										</TD>
										<TD >
											<INPUT class="txt" id="SignDate" style="WIDTH: 100%; HEIGHT: 100%" maxLength="100" dm_name="合同签约日期"> 
										</TD>
									</TR>
									
									<TR height="25">
										<TD>
											经办人
										</TD>
										<TD>
											<INPUT class="txt" id="Jbr" style="WIDTH: 100%; HEIGHT: 100%" maxLength="4000"
												dm_name="经办人">
										</TD>
										<TD>
											经办部门
										</TD>
										<TD >
											<INPUT class="txt" id="JbDeptName" style="WIDTH: 100%; HEIGHT: 100%" maxLength="100" dm_name="经办部门"> 
										</TD>
									</TR>
									
									<TR height="70" id="UseCostInfoTr">										
										<TD colspan=4>
											<table  id="tBudgetInfo" cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed" id="UseCostInfoTb1">
                                                <col width=70/><col width=50 /><col /><col width="25" align="right"/><col width=70/>
                                                <tr>
                                                    <td align=right></td> 
                                                    <td>合约规划</td>
                                                    <td><input type="text" class="txt" readOnly ro="0" name="UseCostInfo" value="" maxlength="2000" onmouseover="openViewLayer(this)"></td>
                                                    <td align="right"><img style="cursor:hand" src="/_imgs/btn_off_lookup.gif" onclick="ChgUseCost()"></td>
                                                    <td></td>
                                                </tr>
                                                <tr height="5"><td align=right colspan=5></td> </tr>
                                            </table>
                                            <table  id="tStockInfo" cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed" id="UseCostInfoTb2">
                                                <col width=70/><col width=50 /><col /><col width="25" align="right"/><col width=70/>
                                                <tr>
                                                    <td align=right></td> 
                                                    <td>中间科目</td>
                                                    <td><input type="text" class="txt" readOnly ro="0" name="UseStockInfo" value="" maxlength="2000"></td>
                                                    <td align="right"><img style="cursor:hand" src="/_imgs/btn_off_lookup.gif" onclick="SelectCompStock()"></td>
                                                    <td></td>
                                                </tr>
                                            </table>
                                            <table id="tDeptUseInfo" cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT:fixed">
                                                <col width=70/><col width=50 /><col /><col width="25" align="right"/><col width=70/>
                                                <tr>
                                                    <td align=right></td> 
                                                    <td>部门费用</td>
                                                    <td><input type="text" class="txt" readOnly ro="0" name="DeptUseInfo" value="" maxlength="2000" onmousemove="openDeptViewLayer(this)"></td>
                                                    <td align="right"><img style="cursor:hand" src="/_imgs/btn_off_lookup.gif" onclick="SelectDeptUseInfo()"></td>
                                                    <td></td>
                                                </tr>
                                            </table>

                                        </TD>										
									</TR>		
									<TR height="200">
										<TD align=center>
											合同要点及经办部门意见
										</TD>
										<TD colspan=3>
                                            <textarea  style="WIDTH: 100%; HEIGHT:100%" id="TextArea1" cols="140" rows="15"  dm_name="合同要点及经办部门意见"></textarea>
										</TD>										
									</TR>
																		
									<TR>
										<TD COLSPAN="4">
											<table width="100%" cellspacing="0" cellpadding="3" style="table-layout:fixed;">
												<TR>
													<TD class='sec bar'>
														相关附件
													</TD>
												</TR>
												<TR height="50">
													<TD>
														<iframe id="appIfraFJ" src="" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>
													</TD>
												</TR>
											</table>
										</TD>
									</TR>
								</TABLE>								
							</P>
						</TD>
					</TR>					
				</TBODY>
			</TABLE>
		</form>
	</body>
</HTML>